<?php
class AuthMiddleware
{
    /**
     * Example middleware invokable class
     *
     * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
     * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
     * @param  callable                                 $next     Next middleware
     *
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function __invoke($request, $response, $next)
    {
        $userSession=new userSession();
        if(!empty($userSession->get())){
            $response = $next($request, $response);
        }else{
            $uri = $request->getUri();
            $response->getBody()->write($uri);
            return $response->withRedirect('/?from='.$uri, 301);
        }


        return $response;
    }
}